home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / game / shoot / ADescentSrc.lha / descent / ui / number.c < prev    next >
Text File  |  1998-08-08  |  3KB  |  112 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13.  
  14. #include <stdio.h>
  15. #include <stdarg.h>
  16.  
  17. #include "fix.h"
  18. #include "types.h"
  19. #include "gr.h"
  20. #include "ui.h"
  21.  
  22. #define TEXT_EXTRA_HEIGHT 5
  23.  
  24. double ui_input_number( short xc, short yc, char * text, double OrgNumber )
  25. {
  26.     UI_WINDOW * wnd;
  27.     UI_GADGET_INPUTBOX * InputBox;
  28.  
  29.     short i, width, height, avg, x, y;
  30.     short box_width, box_height, text_height, text_width;
  31.     short w, h;
  32.     char string[100];
  33.  
  34.     sprintf( string, "%f", OrgNumber );
  35.  
  36.     box_width = box_height = 0;
  37.  
  38.     gr_set_current_canvas( &grd_curscreen->sc_canvas );
  39.  
  40.     box_width = 8*20;
  41.     box_height = 20;
  42.  
  43.     gr_get_string_size(text, &text_width, &text_height, &avg );
  44.  
  45.     width = box_width + 50;
  46.  
  47.     text_width += avg*6;
  48.     text_width += 10;
  49.  
  50.     if (text_width > width )
  51.         width = text_width;
  52.  
  53.     height = text_height;
  54.     height += box_height;
  55.     height += 4*5;
  56.  
  57.     // Center X and Y
  58.     w = grd_curscreen->sc_w;
  59.     h = grd_curscreen->sc_h;
  60.  
  61.     if ( xc == -1 ) xc = Mouse.x;
  62.     if ( yc == -1 ) yc = Mouse.y - box_height/2;
  63.     if ( xc == -2 ) xc = w/2;
  64.     if ( yc == -2 ) yc = h/2;
  65.  
  66.     x = xc - width/2;
  67.     y = yc - height/2;
  68.  
  69.     // Make sure that we're onscreen
  70.     if (x < 0 ) x = 0;
  71.     if ( (x+width-1) >= w ) x = w - width;
  72.     if (y < 0 ) y = 0;
  73.     if ( (y+height-1) >= h ) y = h - height;
  74.  
  75.  
  76.     wnd = ui_open_window( x, y, width, height, WIN_DIALOG );
  77.  
  78.     y = TEXT_EXTRA_HEIGHT + text_height/2 - 1;
  79.  
  80.     ui_string_centered( width/2, y, text );
  81.  
  82.     y = 2*TEXT_EXTRA_HEIGHT + text_height;
  83.  
  84.     y = height - TEXT_EXTRA_HEIGHT - box_height-10;
  85.  
  86.     InputBox = ui_add_gadget_inputbox( wnd, 10, y, 20, 20, string );
  87.  
  88.     ui_gadget_calc_keys(wnd);
  89.  
  90.     //key_flush();
  91.  
  92.     wnd->keyboard_focus_gadget = (UI_GADGET *)InputBox;
  93.  
  94.     while(1)
  95.     {
  96.         ui_mega_process();
  97.         ui_window_do_gadgets(wnd);
  98.  
  99.         if (InputBox->pressed) break;
  100.     }
  101.  
  102.     ui_close_window(wnd);
  103.  
  104.     OrgNumber = atof(inputbox->text);
  105.  
  106.     return OrgNumber;
  107.  
  108. }
  109.  
  110.  
  111. 
  112.